package com.jz.community.moduleshoppingguide.home.ui.activity;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.widget.ImageView;
import android.widget.TextView;

import com.flyco.tablayout.SlidingTabLayout;
import com.jz.community.basecomm.base.BaseMvpActivity;
import com.jz.community.moduleshoppingguide.R;
import com.jz.community.moduleshoppingguide.R2;
import com.jz.community.moduleshoppingguide.home.bean.HotSaleAllBean;
import com.jz.community.moduleshoppingguide.home.bean.HotSaleShowBean;
import com.jz.community.moduleshoppingguide.home.presenter.BestSellersPresenter;
import com.jz.community.moduleshoppingguide.home.ui.BestSellersView;
import com.jz.community.moduleshoppingguide.home.ui.adapter.BestSellersPageAdapter;

import butterknife.BindView;

public class BestSellersActivity extends BaseMvpActivity<BestSellersView.View, BestSellersPresenter> implements BestSellersView.View {


    @BindView(R2.id.title_back_left)
    ImageView titleBackLeft;
    @BindView(R2.id.title_name)
    TextView titleName;
    @BindView(R2.id.st_sliding_category)
    SlidingTabLayout stSlidingCategory;
    @BindView(R2.id.viewpager_goods)
    ViewPager viewpagerGoods;
    @BindView(R2.id.title_toolbar)
    Toolbar titleToolbar;
    int message;


    @Override
    protected int getContentView() {
        return R.layout.module_shoppingguide_activity_channel;
    }

    @Override
    protected BestSellersPresenter createPresenter() {
        return new BestSellersPresenter(this);
    }


    @Override
    protected void initDatas() {
        String title_name = getIntent().getStringExtra("name");
        message = getIntent().getIntExtra("message", 0);
        titleName.setText(title_name);
        setImmersionBar(titleToolbar);
        mPresenter.chunnelHotSaleShow(message);
    }


    @Override
    protected void addListener() {
        titleBackLeft.setOnClickListener(v -> finish());
    }

    @Override
    public void onFail(String s) {

    }

    @Override
    public void getHotSaleAll(HotSaleAllBean hotSaleAllBean, int type) {

    }

    @Override
    public void getHotSaleShow(HotSaleShowBean hotSaleShowBean) {
        if (hotSaleShowBean != null && hotSaleShowBean.get_embedded() != null && hotSaleShowBean.get_embedded().getContent() != null) {
            viewpagerGoods.setAdapter(new BestSellersPageAdapter(getSupportFragmentManager(), hotSaleShowBean.get_embedded().getContent(), message));
            stSlidingCategory.setViewPager(viewpagerGoods);
        }
    }

    @Override
    public Context getContext() {
        return this;
    }
}
